<script setup>

import {defineProps, reactive} from "vue";
import {reviewResult, updateResult} from "@/api/api";
import {message} from "ant-design-vue";

const props = defineProps({
  data: Object,
  role: Number
})

const information = reactive({
  PaperTitle: props.data.info.PaperTitle,
  Journal: props.data.info.Journal,
  IssueNumber: props.data.info.IssueNumber,
  VolumeNumber: props.data.info.VolumeNumber,
  PageRange: props.data.info.PageRange,
  IndexingLevel: props.data.info.IndexingLevel,
  AuthorList: props.data.info.AuthorList,
  FirstAuthor:props.data.info.FirstAuthor,
  CorrespondingAuthor: props.data.info.CorrespondingAuthor,
  PublicationDate: props.data.info.PublicationDate,
  ImpactFactor: props.data.info.ImpactFactor,
  PaperURL: props.data.info.PaperURL,
  SubmissionDate: props.data.info.SubmissionDate,
  msg: ''
})

const postData = reactive({
  id: props.data.id,
  master: props.data.master,
  review: props.data.review,
})

const reviewed = (sta) => {
  console.log(sta)
  const resdata = {
    id: postData.id,
    master: postData.master,
    review: sta,
    info: {
      PaperTitle: information.PaperTitle,
      Journal: information.Journal,
      IssueNumber: information.IssueNumber,
      VolumeNumber: information.VolumeNumber,
      PageRange: information.PageRange,
      IndexingLevel: information.IndexingLevel,
      AuthorList: information.AuthorList,
      FirstAuthor:information.FirstAuthor,
      CorrespondingAuthor: information.CorrespondingAuthor,
      PublicationDate: information.PublicationDate,
      ImpactFactor: information.ImpactFactor,
      PaperURL: information.PaperURL,
      SubmissionDate: information.SubmissionDate,
      msg: information.msg
    }
  }
  console.log(123)
  console.log(resdata)
  reviewResult(resdata).then((res) => {
    console.log(res.data)
    location.reload()
  })
}

const update = () => {
  const resdata = {
    id: postData.id,
    master: postData.master,
    review: 0,
    info: {
      PaperTitle: information.PaperTitle,
      Journal: information.Journal,
      IssueNumber: information.IssueNumber,
      VolumeNumber: information.VolumeNumber,
      PageRange: information.PageRange,
      IndexingLevel: information.IndexingLevel,
      AuthorList: information.AuthorList,
      FirstAuthor:information.FirstAuthor,
      CorrespondingAuthor: information.CorrespondingAuthor,
      PublicationDate: information.PublicationDate,
      ImpactFactor: information.ImpactFactor,
      PaperURL: information.PaperURL,
      SubmissionDate: information.SubmissionDate,
      msg: information.msg
    }
  }
  console.log(123)
  console.log(resdata)
  updateResult(resdata).then(res => {
    if(res.data.status !== 200){
      message.warn(res.data.msg)
    }else{
      location.reload()
    }
  })
}

</script>

<template>
<div>
  <div v-if="role === 2">
    <div>论文名称: </div>
    <a-input :disabled="true" v-model:value="information.PaperTitle" :placeholder="information.PaperTitle" />
    <div>期刊: </div>
    <a-input :disabled="true" v-model:value="information.Journal" :placeholder="information.Journal" />
    <div>期号: </div>
    <a-input :disabled="true" v-model:value="information.IssueNumber" :placeholder="information.IssueNumber" />
    <div>卷号: </div>
    <a-input :disabled="true" v-model:value="information.VolumeNumber" :placeholder="information.VolumeNumber" />
    <div>页码: </div>
    <a-input :disabled="true" v-model:value="information.PageRange" :placeholder="information.PageRange" />
    <div>检索级别: </div>
    <a-input :disabled="true" v-model:value="information.IndexingLevel" :placeholder="information.IndexingLevel" />
    <div>作者名单: </div>
    <a-input :disabled="true" v-model:value="information.AuthorList" :placeholder="information.AuthorList" />
    <div>第一作者: </div>
    <a-input :disabled="true" v-model:value="information.FirstAuthor" :placeholder="information.FirstAuthor" />
    <div>通讯作者: </div>
    <a-input :disabled="true" v-model:value="information.CorrespondingAuthor" :placeholder="information.CorrespondingAuthor" />
    <div>发表日期: </div>
    <a-input :disabled="true" v-model:value="information.PublicationDate" :placeholder="information.PublicationDate" />
    <div>影响因子: </div>
    <a-input :disabled="true" v-model:value="information.ImpactFactor" :placeholder="information.ImpactFactor" />
    <div>论文链接: </div>
    <a-input :disabled="true" v-model:value="information.PaperURL" :placeholder="information.PaperURL" />
    <div>填报日期: </div>
    <a-input :disabled="true" v-model:value="information.SubmissionDate" :placeholder="information.SubmissionDate" />
    <div>指导教师编号: </div>
    <a-input :disabled="true" v-model:value="postData.master" :placeholder="postData.master" />
    <div>评价：</div>
    <a-textarea v-model:value="information.msg">
    </a-textarea>
    <div>
      <a-button @click="reviewed(1)">通过</a-button>
      <a-button @click="reviewed(-1)">拒绝</a-button>
    </div>
  </div>

  <div v-if="role === 3">
    <div>论文名称: </div>
    <a-input :disabled="false" v-model:value="information.PaperTitle" :placeholder="information.PaperTitle" />
    <div>期刊: </div>
    <a-input :disabled="false" v-model:value="information.Journal" :placeholder="information.Journal" />
    <div>期号: </div>
    <a-input :disabled="false" v-model:value="information.IssueNumber" :placeholder="information.IssueNumber" />
    <div>卷号: </div>
    <a-input :disabled="false" v-model:value="information.VolumeNumber" :placeholder="information.VolumeNumber" />
    <div>页码: </div>
    <a-input :disabled="false" v-model:value="information.PageRange" :placeholder="information.PageRange" />
    <div>检索级别: </div>
    <a-input :disabled="false" v-model:value="information.IndexingLevel" :placeholder="information.IndexingLevel" />
    <div>作者名单: </div>
    <a-input :disabled="false" v-model:value="information.AuthorList" :placeholder="information.AuthorList" />
    <div>第一作者: </div>
    <a-input :disabled="false" v-model:value="information.FirstAuthor" :placeholder="information.FirstAuthor" />
    <div>通讯作者: </div>
    <a-input :disabled="false" v-model:value="information.CorrespondingAuthor" :placeholder="information.CorrespondingAuthor" />
    <div>发表日期: </div>
    <a-input :disabled="false" v-model:value="information.PublicationDate" :placeholder="information.PublicationDate" />
    <div>影响因子: </div>
    <a-input :disabled="false" v-model:value="information.ImpactFactor" :placeholder="information.ImpactFactor" />
    <div>论文链接: </div>
    <a-input :disabled="false" v-model:value="information.PaperURL" :placeholder="information.PaperURL" />
    <div>填报日期: </div>
    <a-input :disabled="false" v-model:value="information.SubmissionDate" :placeholder="information.SubmissionDate" />
    <div>指导教师编号: </div>
    <a-input :disabled="false" v-model:value="postData.master" :placeholder="postData.master" />
    <div>
      <a-button @click="update">
        Update
      </a-button>
    </div>
  </div>
</div>
</template>

<style scoped>
div{
  margin-top: 1rem;
}
</style>